<!-- 考试-->
<template>
  <div class="app-container">
    
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="课件" prop="courseName">
        <el-input v-model="queryParams.courseName" placeholder="请输入课件名" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="课件分类" prop="status">
        <el-select v-model="queryParams.professionId" placeholder="课件类型" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.sys_course_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="searchTable()">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="emptySearch()">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addCourse">新增课件</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-col :span="24">
      <el-table :data="tableData" border>
        <el-table-column prop="courseName" label="课件名" align="center">
        </el-table-column>
        <el-table-column prop="courseSecond" label="课件时长" align="center">
          <template slot-scope="scope">
            {{ formatDuration(scope.row.courseSecond) }} <!-- 使用格式化方法 -->
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="400" align="center">
          <template slot-scope="scope">
            <el-button @click="previewVideo(scope.row)" type="text" size="small">预览</el-button>
            <el-button @click="importQuestion(scope.row)" type="text" size="small">上传题目</el-button>
            <el-button @click="delCou(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <el-row>
      <el-col>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
          @pagination="getList" />
      </el-col>
    </el-row>

    <AddCourse ref="AddCourseRef"></AddCourse>
    <PreviewVideo ref="previewVideo"></PreviewVideo>
    <ImportQuestion ref="dialogRefs"></ImportQuestion>
  </div>
</template>


<script>
import { getCourseList, delCourse } from "@/api/course/index.js";
import AddCourse from "./components/add-course.vue";
import PreviewVideo from "./components/preview-video.vue";
import ImportQuestion from "./components/import-question.vue";

export default {
  components: {
    AddCourse,
    PreviewVideo,
    ImportQuestion
  },
  dicts: ["sys_course_type"],
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      dialogTableVisible: false,
      tableData: [],
      params: {},
      total: 1,
      examPaperId: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        courseName: undefined,
        professionId: undefined,
        courseType: 1,
      },
    };
  },
  computed: {},
  created() {
    this.getList();
  },
  mounted() { },
  methods: {
    // 点击页码及上一页下一页按钮操作
    currentChange(val) {
      this.queryParams.current = val;
      //刷新表格
      this.getList();
    },
    //每页展示几条按钮操作
    sizeChange(val) {
      this.queryParams.size = val;
      //刷新表格
      this.getList();
    },
    //获取试卷列表
    getList() {
      getCourseList(this.queryParams).then((res) => {
        console.log(res);
        if (res.code === 200) {
          this.tableData = res.rows;
          this.total = res.total;
        }
      });
    },
    //搜索
    searchTable() {
      this.getList();
    },
    //重置搜索框
    emptySearch() {
      queryParams.courseName = "";
      queryParams.professionId = undefined;
      this.getList();
    },
    //新增课件
    addCourse() {
      this.$refs.AddCourseRef.onOpen();
    },

    //预览视频
    previewVideo(row) {
      //打开弹窗
      this.$refs.previewVideo.show(row.courseUrl);
    },

    //上传题目
    importQuestion(row) {
      this.$refs.dialogRefs.show(row.courseId);
    },

    //删除课件
    delCou(row) {
      if (confirm("确定删除该课件吗?")) {
        delCourse({
          courseId: row.courseId
        }).then((res) => {
          if (res.code === 200) {
            //刷新列表
            this.getList();
          }
        });
      }
    },
  },
};
</script>>

<style>
.box {
  height: calc(100vh - 120px);
  font-size: 14px;
  line-height: 28px;
}

.title {
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 10px;
  padding-top: 20px;
  margin-bottom: 10px;
  border-bottom: #eee 1px dotted;
}

.tags span {
  margin-right: 10px;
}

.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: hwb(210 95% 5%);
}

.bg-purple {
  border: 0px solid cornflowerblue;
  height: 200px;
}

.app-container {
  height: 100%;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 60px;
}
</style>